<?php

defined('BY_JYA') or exit('error');
list($day)=$arguments;


	$day = (int) $day;

	if ($day != 0) {
		$createtime1 = strtotime(date('Y-m-d', time() - ($day * 3600 * 24)));
		$createtime2 = strtotime(date('Y-m-d', time()));
	}
	else {
		$createtime1 = strtotime(date('Y-m-d', time()));
		$createtime2 = strtotime(date('Y-m-d', time() + (3600 * 24)));
	}

	$sql = 'SELECT o.id,o.price,o.createtime,s.mid,s.name FROM' . tablename('jy_weishop_order') . ' o inner JOIN ' . tablename('jy_weishop_store_worker') . " s ON o.verifymid=s.mid   WHERE \r\n        o.uniacid=:uniacid AND o.ismr=0  AND   o.status =3  AND o.deleted=0 AND o.createtime between :createtime1 and :createtime2";
	$param = array(':uniacid' => $_SESSION['uniacid'], ':createtime1' => $createtime1, ':createtime2' => $createtime2);
	$pdo_res = pdo_fetchall($sql, $param);
	$allprice = 0;
	$price = 0;
	$saler = array();

	foreach ($pdo_res as $key => $arr) {
		$allprice += $arr['price'];
		$saler[$arr['mid']]['name'] = $arr['name'];
		$saler[$arr['mid']]['price'] += $arr['price'];
		$saler[$arr['mid']]['count'] += 1;
	}

	$result = array('price' => round($allprice, 1), 'count' => count($pdo_res), 'saler' => $saler);
	return $result;
